﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Polly;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace SageKing.AspNetCore.Extensions;

public static class ModelStateExtensions
{
    public static IDictionary<string, string[]> GetAllErrors(this ModelStateDictionary modelState)
    {
        var result = modelState
                .Where(e => e.Value.Errors.Count > 0)
                .ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                );
        return result;
    }
}
